#include<vector>
#include<iostream>
using std::vector;


class Solution {
public:
    int lengthOfLIS(vector<int>& nums) {
        vector<int> tail(nums.size(), nums[0]);
        int len = 1;
        int v;
        int lo, hi, mi;
        for (int i = 1; i < nums.size(); i++) {
            v = nums[i];
            if (v > tail[len-1]) {
                tail[len++] = v;
                continue;
            }
            // else
            hi = len - 1;
            lo = 0;
            int pos = -1;
            // for (int i = 0; i < len; i++) std::cout << tail[i] << " ";
            //     std::cout << "\n";
            while (lo <= hi) {
                
                mi = (hi + lo) / 2;
                if (tail[mi] < v) {
                    pos = mi;
                    lo = mi + 1;
                }
                else if (tail[mi] > v) {
                    hi = mi - 1;
                }
                else {
                    pos = mi - 1;
                    break;
                }
            }
            tail[pos+1] = v;
            

        }
        return len;
    }
};

int main() {
    int tmp;
    vector<int> nums;
    while (std::cin >> tmp) {
        nums.push_back(tmp);
        std::cout << tmp << " ";
    }
    std::cout << "\n";
    auto ans = Solution().lengthOfLIS(nums);
    std::cout << ans << "\n";
    return 0;
}